package caiziyou.com.designpattern.observer.improve;

import java.util.ArrayList;
import java.util.List;

public class WeatherData implements Subject{
	
	private float temperature;
	private float pressure;
	private float humidity;
	
	private List<Observer> observers = new ArrayList<>();

	public void registerObserver(Observer o) {
		observers.add(o);
	}

	public void removeObserver(Observer o) {
		observers.remove(o);		
	}

	public void notifyObservers() {
		observers.forEach(o->o.update(temperature, pressure, humidity));
	}

	public void setData(float temperature, float pressure, float humidity) {
		this.temperature = temperature;
		this.pressure = pressure;
		this.humidity = humidity;
		notifyObservers();
	}
}
